package idoc.index;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Random;

public class RandomAccess {
	
	public static void main(String[] args) throws IOException {
		Random random=new Random();
		RandomAccessFile file = new RandomAccessFile("1.dat", "rw");
		file.seek(100000000);
		file.writeLong(1000L);
		for(long l =0;l<1000000;l+=8){
			file.seek(l);
			file.writeLong(l);
		}
		long t1 =System.currentTimeMillis();
		
		for(long i=0;i<300000;i++){
			long r = random.nextInt(300000);
			while(r%8>0){
				r++;
			}
			file.seek(r);
		
			long l=file.readLong();
			//System.out.println(l);
		}
		long t2 =System.currentTimeMillis();
		System.out.println(t2-t1);
	
	}
}
